/*
 * Copyright (c) 2023 Cshoo Org. All Rights Reserved.
 */

package org.cshoo.tattoo.authorize.domain.repository;

import org.cshoo.tattoo.authorize.domain.po.Authority;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.List;

/**
 * @author 杨翼
 * @since 1.0
 */
public interface IAuthorityRepository extends CrudRepository<Authority, Long> {

    /**
     * 根据微服务查询权限点，即查询某个微服务下的全部权限点
     *
     * @param microserviceId 微服务id
     * @return 权限点列表
     */
    List<Authority> findByMicroserviceId(Long microserviceId);

    @Query("select at from Authority at inner join RoleAuthorityRelation rar on at.id = rar.authorityId where rar.roleId = ?1")
    List<Authority> findByRoleId(Long roleId);
}
